#include "my_switch.h"

My_switch::My_switch(const QString &title, QWidget *parent) : QWidget(parent)
{
    name = new QLabel(title, this);
    name->setAlignment(Qt::AlignCenter);
    value = new My_led(20 ,this);
    btn_open = new QPushButton("打开", this);
    btn_close = new QPushButton("关闭", this);
    box = new QHBoxLayout();
    box->addWidget(name);
    box->addWidget(value);
    box->addWidget(btn_open);
    box->addWidget(btn_close);
    box->setContentsMargins(LEFT_M, TOP_M, RIGHT_M, BOTTOM_M);
    box->setSpacing(SPACE_SON);
    this->setLayout(box);
}

void My_switch::setEnabled(bool flag)
{
    btn_open->setEnabled(flag);
    btn_close->setEnabled(flag);
}

void My_switch::set_status(int num)
{
    value->set_color(num);
}
